package sg.edu.nus.iss.team2s.jass.control;
/**
 * @author Zaw Htet Wai
 *
 */
import sg.edu.nus.iss.team2s.jass.dto.User;
import sg.edu.nus.iss.team2s.jass.dao.DAOException;
import sg.edu.nus.iss.team2s.jass.dao.DAOInterface;
import sg.edu.nus.iss.team2s.jass.dao.DAOFactory;

public class LoginController {
	public static boolean validateLogin(String userName, String passWord){
		DAOInterface userInterface = (DAOInterface)DAOFactory.getInstance().getDAO(User.class.getName());
		User user = null;
		try {
			user = (User)userInterface.get(userName + "|" + passWord);
			if(user != null)
			{
				MainController.setUser(user);	
				return true;
			}
			
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();			
		}
		return false;
	}
	
	public static boolean checkLoginStatus(){
		User user = null;
		try{
			user = (User)MainController.getUser();
		}
		catch(Exception e){
			e.printStackTrace();
		}
		if(user != null)
			return true;
		return false;
	}
}
